home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / tclMotif-1.4 / programs / prog63 < prev    next >
Encoding:
Text File  |  1995-06-29  |  1.1 KB  |  54 lines

  1. # testing item position calculation
  2.  
  3.  
  4. proc indexToY {w n} {
  5.   # calculate the Y co-ord for an index in the list
  6.   $w getValues \
  7.     -height h -itemCount count \
  8.     -visibleItemCount vis \
  9.     -topItemPosition top
  10.  
  11.   set item_height [expr {$h / $vis}]
  12.   set vis_index [expr {$n - $top + 1}]
  13.  
  14.   set y [expr {((2*$vis_index -1) * $item_height) / 2}]
  15.   return $y
  16. }
  17.  
  18. proc buttonPress {w n} {
  19.   # simulate a button press 
  20.   return [$w callActionProc ListBeginSelect() \
  21.                 -type ButtonPress \
  22.                 -x 0 -y [indexToY $w $n]]
  23. }
  24.  
  25. proc buttonRelease {w n} {
  26.   # simulate a button release 
  27.   return [$w callActionProc ListEndSelect() \
  28.                 -type ButtonRelease \
  29.                 -x 0 -y [indexToY $w $n]]
  30. }
  31.  
  32. xtAppInitialize -class Program
  33.  
  34. xmScrolledList .list managed \
  35.     -items "a b c d e f g h i j" \
  36.     -itemCount 10 \
  37.     -selectionPolicy single_select \
  38.     -visibleItemCount 5 \
  39.     -topItemPosition 3
  40. .list singleSelectionCallback {puts stdout %item}
  41.  
  42. .list getValues -height h
  43. puts stdout "height: $h"
  44.  
  45. set n 7
  46. puts stdout "Pressing button $n"
  47. buttonPress .list $n
  48. buttonRelease .list $n
  49.     
  50.  
  51. . realizeWidget
  52.  
  53. . mainLoop
  54.